package com.szrt.day20170504.ch06;

public class TicketThread  implements Runnable {
	
	//跟类走
	private static int ticket=100;

	@SuppressWarnings("static-access")
	@Override
	public void run() {
		for(int index =1;index<=100; index++){
			try {
				synchronized (TicketThread.class) {
					if(ticket>=1){
						Thread thread = Thread.currentThread();
						System.out.println(thread.getName() +"开始买票" + ticket);
						//休息10毫秒 拿到当前线程
						thread.sleep(10);
						ticket = ticket - 1;
					}
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			
			
			
		}
		
	}
	
	
	
	

}
